#include <unistd.h>
#include <chrono>
#include <iostream>
#include <vector>
#include "log.h"

#include "ThreadPool.hpp"

int main() {
    auto threads = std::make_unique<ThreadPool>(sysconf(_SC_NPROCESSORS_ONLN));
    std::vector<std::future<int>> results;

    int cnt = 100;
    while (cnt--) {
        results.emplace_back(
            threads->enqueue([cnt] {
                LOG_DEBUG("cnt:%d", cnt);
                std::this_thread::sleep_for(std::chrono::seconds(1));
                return cnt;
            }));
    }
    LOG_DEBUG("End of enqueue task.");

    for (auto&& result : results) {
        static int index = 0;
        LOG_DEBUG("index:%d\tvalue:%d", index++, result.get());
    }
    LOG_DEBUG("End of threads joined.");

    return 0;
}